<template>
  <div>
    <basic-container>
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>数据</el-breadcrumb-item>
        <el-breadcrumb-item>产品</el-breadcrumb-item>
        <el-breadcrumb-item>每日各渠道新增情况</el-breadcrumb-item>
      </el-breadcrumb>
    </basic-container>
    <basic-container>
      <avue-crud
        ref="crud"
        :data="data"
        v-model="form"
        :option="option"
        :page.sync="page"
        @on-load="getList"
        @refresh-change="refreshChange"
        @search-reset="from = {}"
        @search-change="searchChange"
      >
        <!-- 自定义按钮 -->
        <template slot="menuLeft">
          <el-button
            type="primary"
            icon="el-icon-download"
            size="small"
            plain
            @click="handleExcel()"
            >导出Excel</el-button
          >
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import { common } from "@/api/cat/httpRequest";
import { catUrl } from "@/config/env";
import { handleExcelCat } from "@/api/exportCommon";
import { productData as baseURL,getGroupList } from "@/api/cat/baseUrls";
export default {
  data() {
    return {
      loading:false,
      page: {
        total: 0,
        pageSize: 10,
      },
      type: true,
      data: [],
      params: {},
      form: {},
      default: {
        orderByList: "statistics_date&DESC,channel_id&DESC",
      },
      option: {
        index: true,
        indexLabel: "编号",
        addBtn: false,
        editBtn: false,
        viewBtn: false,
        delBtn: false,
        excelBtn: false,
        selection: true,
        border: true,
        menu: false,
        column: [
          {
            label: "日期",
            prop: "statistics_date_search",
            type: "date",
            format:"yyyy-MM-dd",
            valueFormat: "yyyy-MM-dd",
            search: true,
            hide:true
          },
          {
            label: "日期",
            prop: "statistics_date",
            type: "datetime",
            format:"yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            search: false,
          },
          {
            label:'版本号',
            type:'input',
            prop: "app_version",
            search: true,
            placeholder:'请输入渠道号'
          },
          {
            label: "渠道号",
            type: "input",
            prop: "channel_id",
            search: true,
            placeholder: "请输入渠道号",
          },
          {
            label: "用户群组",
            prop: "group_id",
            type: "select",
            hide:true,
            search: true,
            dicUrl: `${catUrl}${getGroupList.getGroupList}`,
            dicFormatter: (res) => {
              return res.source;
            },
            props: {
              label: "group_name",
              value: "group_id",
            },
                         editDisplay: false,

          },
          {
            label: "新增用户数",
            prop: "add_user_num",
            type: "input",
          }, 
        ],
      },
    };
  },
  methods: {
            //数据导出
    async handleExcel() {
      this.loading = true;
      //处理搜索条件
      let params = {...this.$refs.crud.searchForm};
      params.orderByList = "statistics_date&DESC";

      //日期
       if(params.statistics_date_search){
         params.statistics_date = "$date"+params.statistics_date_search;
         delete params.statistics_date_search;
       }

      //调用导出接口
      handleExcelCat(
        this.$export,
        baseURL.getRealtimeAddList,
        { ...params, ...this.default },
        "每日各渠道新增情况",
        this.page.total,
        [...this.option.column]
      );
      this.loading = false;
    },
    /**获取列表 */
    async getList() {
      this.loading = true;
      //清空表格列表
      this.data = [];
      //发送请求获取数据
      let response = await common(
        baseURL.getRealtimeAddList,
        { ...this.params, ...this.default },
        this.page,
        "POST"
      );
      this.page = response.page;
      this.data = response.data;
      this.loading = false;
    } /**刷新 */,
    refreshChange() {
      this.getList();
    },
    /**搜索 */
    searchChange(params, done) {
      params.statistics_date = params.statistics_date_search?"$date"+params.statistics_date_search:'';
      delete params.statistics_date_search;
       params.channel_id = params.channel_id?'$in'+params.channel_id:''
      this.params = params;
      this.page.currentPage = 1;
      this.getList();
      if (done) done();
    },
  },
};
</script>